package cutword;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Date;
import java.util.Hashtable;

public class Pagerank {
	
	public double[] rank;
	public double[][] linknetwork;
	
	public static void main(String[] args) throws Exception
	{
		
		
		int t=new Date().getHours();
		System.out.print(t);
//		double[] myrank={1.0,1.0,1.0,1.0};
//		double[][] mylink={
//				{0,1,2,3},
//				{2,0,2,2},
//				{1,0,0,2},
//				{2,1,3,0}};
//		Pagerank P=new Pagerank();
//		double[] r=P.getpagerank(myrank, mylink);
//		for(int i=0;i<r.length;i++)
//			System.out.println(r[i]);
	}
	
	public double[] getpagerank(double[] Rank,double[][] link) throws Exception
	{
		Integer i,j;
		double Sum;
		for(i=0;i<link.length;i++)
		{
			Sum=0;
			for(j=0;j<link[0].length;j++)
				Sum=Sum+link[i][j];
			if(Sum>0)
			{
				for(j=0;j<link[0].length;j++)
					link[i][j]=link[i][j]/Sum;
			}
		}
		
		double[] OldRank=Rank;
		double k=0;
		
		double alpha=0.85;
		
		for(int iter=0;iter<10;iter++)
		{
			for(j=0;j<link.length;j++)
			{
				for(i=0;i<link.length;i++)
				{
					k=(alpha*link[i][j]+1-alpha)*OldRank[i];
				}
				Rank[j]=k;
			}
			OldRank=Rank;
			System.out.println("===============");
			for(int m=0;m<Rank.length;m++)
			{
				System.out.println(Rank[m]);
			}
		}
		return Rank;
	}
	
	
	
	public double[] initRank(double[] Rank)
	{
		this.rank=Rank;
		return this.rank;
	}
	
	public double[] initRank(Integer num)
	{
		double[] Rank=new double[num];
		for(int i=0;i<num;i++)
		{
			Rank[i]=1;
		}
		this.rank=Rank;
		return Rank;	
	}
	
	public double[][] initLinknetwork(double[][] link)
	{
		this.linknetwork=link;
		return this.linknetwork;
	}
	

}
